<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>单例模式</title>
</head>
<body>
    
</body>
</html>
<script>
    var Singleton = function(name){
        this.name = name;
        this.instance = null;
    }
    Singleton.prototype.getName = function(){
        return this.name;
    }

    Singleton.getInstance = function(name){
        if(!this.instance){
            this.instance = new Singleton(name);
        }
        return this.instance;
    }

    var a = Singleton.getInstance("zhangaiping");
    var b =Singleton.getInstance("zhangailing");
    console.log(a === b);

    //
</script>